import { createRouter, createWebHistory } from "vue-router"

// 约定式路由
const getRoutes = () => {
  const files = import.meta.glob("../views/*.vue")
  const routes = Object.entries(files).map(([file, module]) => {
    const name = file.match(/\.\.\/views\/([^/]+?)\.vue/i)?.[1]
    return {
      path: "/" + name,
      component: module
    }
  })
  return routes
}

const router = createRouter({
  routes: getRoutes(),
  history: createWebHistory()
})

export default router
